package com.fzz.dao;

import com.fzz.domain.Admin;
import com.fzz.domain.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Mapper
public interface AdminMapping {

    @Select("select * from tb_admin where adminName=#{adminName} and password=#{password}")
    public Admin adminLogin(@Param("adminName") String adminName, @Param("password") String password);

    @Update("update tb_admin set adminName=#{adminName},password=#{password},email=#{email},phone=#{phone},address=#{address}")
    public Integer adminUpdate(Admin admin);

    //分页查询
    @Select("<script> " +
            "select * from tb_user where 1=1 " +
            "<if test='id!=null'>and id=#{id}</if>" +
            "<if test='username!=null'> and username like concat('%',#{username},'%')</if>" +
            "</script>")
    public List<User> selectUserWithPage(@Param("id") Integer id,@Param("username") String username);

    //根据id
    @Select("select * from tb_user where id=#{id}")
    public User seleteUserById(@Param("id") Integer id);

    //修改用户信息
    @Update("update tb_user set username=#{username},password=#{password},email=#{email} where id=#{id}")
    public Integer editUserInfo(User user);

    //删除用户信息
    @Delete("delete from tb_user where id=#{id}")
    public Integer deleteUserInfoById(@Param("id") Integer id);
}
